﻿using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.xml.simpleparser;
using System.IO;

namespace TurtleEngine.Helper.PDFWritter
{
	 /// <summary>
	 ///
	 /// </summary>
	 internal class PDFWriter
	 {
		  /// <summary>
		  /// Creates the PDF file.
		  /// </summary>
		  /// <param name="xmlFileName">Name of the XML file.</param>
		  /// <param name="pdfFileName">Name of the PDF file.</param>
		  public static void CreatePDFFile(string xmlFileName, string pdfFileName)
		  {
				string xmlFile = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Path.GetTempFileName()));
				File.WriteAllText(xmlFile + ".xml", xmlFileName);

				var document = new Document();
				PdfWriter.GetInstance(document, new FileStream(pdfFileName, FileMode.Create));

				//ITextHandler xmlHandler = new ITextHandler(document);
				//xmlHandler.Parse(xmlFile + ".xml");
				document.Open();
				SimpleXMLParser.Parse((ISimpleXMLDocHandler)document,
									new StreamReader(pdfFileName).BaseStream);
				document.Close();
		  }
	 }
}